package com.project.class8_16;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class PressXml {
    @Deprecated
    public List<Student> getList(){
        List<Student> studentList = new ArrayList<>();

        Date d = new Date(120,9,30);

        SAXReader sax = new SAXReader();
        try {
            //读取XML文档，将读取信息存放到document对象中
            Document doc = sax.read("src/main/java/com/project/class8_16/xml/lovoClass.xml");

            //选择节点，一个student标记就是一个Node对象
            List<Element> elementList = doc.selectNodes("/lovoClass/student");
            for(Element em : elementList){
                Student s = new Student();
                //将student标签中的code属性取出，封装为学生对象的code属性
                s.setCode(em.attributeValue("code"));
                s.setPhone(em.attributeValue("tel"));
                //将student标签的子元素name中间的文本取出，封装为学生对象的name属性
                s.setName(em.elementText("name"));
                s.setEdu(em.elementText("edu"));
                s.setAge(Integer.parseInt(em.elementText("age")));

                studentList.add(s);
            }


        } catch (Exception e) {
            e.printStackTrace();
        }


        return studentList;
    }
}
